package kin.json;

import java.util.Collection;

import kin.system.util.StringUtil;

import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.AnnotatedField;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;


public class MyNameStrategy extends PropertyNamingStrategy {
	
	
	
	@Override 
	public String nameForGetterMethod(MapperConfig config, AnnotatedMethod method, String defaultName) 
	{
		//System.out.println("type:"+method.getRawReturnType());
		Class type = null;
		try {
			type = method.getRawReturnType();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(!type.isPrimitive()&&!type.isArray()&&!type.isInterface()){

		String packageName=type.getPackage().getName();
		 if((packageName.equals("kin.bean.system")||packageName.equals("kin.test")||packageName.equals("kin.bean.security")||packageName.equals("kin.bean.customer"))&&!defaultName.equals("parent")){
			 String name= StringUtil.fristLetterLowerCase(type.getSimpleName());
			 return convert(name+"_id"); 
		}
		}
		else{
			
		return convert(defaultName);
		}
		return convert(defaultName); 
		
		}
	
	@Override
	public String nameForSetterMethod(MapperConfig config, AnnotatedMethod method, String defaultName) { 
		//System.out.println("ccc");
		String a = convert(defaultName); return a; 
		} 
	
	public String convert(String defaultName ) { 
		//System.out.println("bbb");
		char[] arr = defaultName.toCharArray(); 
		if(arr.length !=0) { 
			if ( Character.isLowerCase(arr[0])){ 
				char upper = Character.toLowerCase(arr[0]); arr[0] = upper; 
				}
			} 
		return new StringBuilder().append(arr).toString(); 
		} 
	
} 
